package com.focus.xyz.union.pages.frontend;

import com.focus.xyz.core.common.keyword.Action;
import com.focus.xyz.core.pages.BasePage;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

/**
 * Created by chenmeng on 2016/7/18.
 */
public class BaseInfoPage extends BasePage{
    private Action action;

    @FindBy(xpath = "//input[@id='dev_qq']")
    private WebElement devqq;
    @FindBy(id = "province")
    private WebElement selectPrvince;
    @FindBy(id = "city")
    private WebElement selectCity;
    @FindBy(xpath = "//input[@name='person.address']")
    private WebElement address;
    @FindBy(xpath = "//button[@id='dev_submit_button']")
    private WebElement submitBtn;
    @FindBy(xpath = "//input[@name='company.comName']")
    private WebElement companyName;
    @FindBy(xpath = "//input[@name='company.orgNo']")
    private WebElement orgCode;

    public BaseInfoPage(WebDriver driver, Action action){
        super(driver,action);
        this.action = action;
        PageFactory.initElements(driver,this);
    }

    public void fillBaseInfo(String qq,String province,String city,String addr,String comName,String ordCode) throws Exception{
        if(!action.isElementExsit(By.id("dev_qq"))){
            return;
        }
        if(action.isElementExsit(By.xpath("//input[@name='company.comName']"))){
            action.inputText(companyName,comName);
        }
        if(action.isElementExist(orgCode)){
            action.inputText(orgCode,ordCode);
        }
        action.inputText(devqq,qq);
        action.select(selectPrvince,province);
        action.select(selectCity,city);
        action.inputText(address,addr);
        action.click(submitBtn);
    }
}
